<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/include/service-base-header.jsp" %>
    <title>money</title>
    <style>
        .table tbody tr td, .table th {
            padding: 5px;
        }

    </style>
</head>
<body>
<div class="wrapper">
    <jsp:include page="/include/left_menu.jsp">
        <jsp:param name="index" value="3"/>
    </jsp:include>
    <div class="main-panel">
        <nav class="navbar navbar-expand-lg "
             style="-webkit-box-shadow:0 0 5px rgba(40, 173, 243, 0.0);box-shadow: 0 0 5px rgba(40, 173, 243, 0.0);">
            <div class="container-fluid">
                <div class="navbar-wrapper b-navbar-wapper">
                    <a class="b-navbar-title-active" href="#">资金管理</a>
                </div>
            </div>
        </nav>
        <div class="container-fluid">
            <div class="row" style="margin-left: 3rem;margin-top: 1rem">
                <div style="width: 18rem;">
                    <div class="card card-stats" style="width: 16rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #F1A342 100%">
                                <img src="../image/one.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">提款总额</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="cashMoney"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                        <div class="card-footer">
                            <div class="stats" align="center">
                                <div>
                                    <img src="../image/one.svg" style="width: 2rem;height: 2rem;padding: 0.3rem">
                                    <span onclick="isShowDialog()" style="color:#5274EB;"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div style="width: 18rem;margin-left: 4rem">
                    <div class="card card-stats" style="width: 16rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #6DAC63 100%">
                                <img src="../image/two.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">奖励账户消耗</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="xiaohaoMoney"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                        <div class="card-footer">
                            <div class="stats" align="center">
                                <div>
                                    <img src="../image/set_icon.svg" style="width: 2rem;height: 2rem;padding: 0.3rem">
                                    <span onclick="isShowDialog()" style="color:#5274EB;" id="showDialog">奖励账户设置</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="card card-plain">
                        <div class="card-header card-header-primary">
                            <div class="card-title">提现列表</div>
                            <p class="card-category">审核会员提现</p>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table" id="table">
                                    <thead class=" text-primary">
                                    <tr>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            #
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现订单号
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            发起时间
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现用户
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现金额
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现方式
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            提现到账户
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            操作
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <nav aria-label="page">
                        <ul class="pagination justify-content-center" id="p1">
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>


<div class="modal fade" id="loginModal" tabindex="-1" role="">
    <div class="modal-dialog modal-login" role="document">
        <div class="modal-content">
            <div class="card card-signup card-plain">

                <div class="modal-body">
                    <button type="button" class="close mt-4" data-dismiss="modal" aria-hidden="true"><i
                            class="material-icons">clear</i></button>

                    <form class="form" method="" action="">
                        <p class="description  mt-4 ml-4" style="font-size: 1.2rem;">奖励账户设置</p>
                        <div class="card-body">
                            <div>
                                <div class="togglebutton">
                                    <label style="padding-bottom: 0.4rem">
                                        <span style="color: #555555;">是否开启充值奖励</span>
                                        <input type="checkbox" align="right" id="cb"/>
                                        <span class="toggle" style="margin-left: 8rem;"></span></label>
                                </div>
                                <div class="input-group">
                                    <span style="margin-top: 0.4rem;margin-right: 0.4rem">充值钱数(KSH)</span>
                                    <div><input type="text" id="cardMoney"
                                                style="border-color: #878787; border-style: solid; border-top-width: 0px;border-right-width: 0px; border-bottom-width: 1px;border-left-width: 0px;width: 19rem">
                                    </div>
                                </div>
                                <div class="input-group" style="margin-top: 1rem">
                                    <span style="margin-top: 0.4rem;margin-right: 0.4rem">奖励钱数(KSH)</span>
                                    <div><input type="text" id="cardRewardMoney"
                                                style="border-color: #878787; border-style: solid; border-top-width: 0px;border-right-width: 0px; border-bottom-width: 1px;border-left-width: 0px;width: 19rem">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer justify-content-end" style="padding-bottom: 1rem;margin-right: 0.5rem">
                    <button onclick="updateCardInfo()" class="btn btn-info" id="save_update">保存
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    function findFundManagement() {
        var systemUserId = "<%=session.getAttribute("systemUserId")%>";
        $.ajax({
            url: baseUrl.base + baseUrl.fundManagement + "/findFundManagement",
            type: 'get',
            data: {"userId": systemUserId},
            success: function (data) {
                if (data.code == "0") {
                    var res = data.results;
                    if (null == res.cashMoney) {
                        $("#cashMoney").html(0);
                    } else {
                        $("#cashMoney").html(res.cashMoney);
                    }
                    $("#xiaohaoMoney").html(res.rewardMoney);
                }
            }
        })
    };
    findFundManagement();

    function isShowDialog() {
        findCardInfo();
        $("#loginModal").modal('show');
    }

    /***
     * 查询是否有代金券
     *
     */
    function findCardInfo() {
        $.ajax({
            url: baseUrl.base + baseUrl.CardInfo + "/findCardInfo",
            type: 'get',
            data: {},
            success: function (data) {
                if (data.code == "0") {
                    var res = data.results;
                    if (res == null) {
                    } else {
                        $("#cardMoney").val(res.cardMoney);
                        $("#cardRewardMoney").val(res.cardRewardMoney);
                        if (res.cardState == 1) {
                            $('#cb').prop('checked', true);
                        } else {
                            $('#cb').prop('checked', false);
                        }
                    }
                }
            }
        })
    };

    /***
     *
     修改代金券是否下架 或者 添加
     *
     */
    function updateCardInfo() {
        var data = {};
        var isChecked = $('#cb').prop('checked');
        if (isChecked == true) {
            data.cardState = 1;
        } else {
            data.cardState = 0;
        }
        data.cardMoney = $("#cardMoney").val();
        data.cardRewardMoney = $("#cardRewardMoney").val();
        $.ajax({
            url: baseUrl.base + baseUrl.CardInfo + "/updateCardInfo",
            type: 'get',
            data: data,
            success: function (data) {
                if (data.code == "0") {
                    showNotification('bottom', 'right', '奖励设置成功');
                    $("#loginModal").modal('hide');
                } else {
                    alert(data.msg);
                }
            }
        })
    };

    var page_count = 10;

    /**
     * 获取提现列表
     */
    function findCashInfo() {
        $.ajax({
                url: baseUrl.base + baseUrl.cashInfo + '/findCashInfo',
                type: 'get',
                success: function (data) {
                    if (data.code == "0") {
                        var res = data.results;
                        cutPagination(1, res);
                        $("#p1").pagination({
                            totalData: res.length,
                            showData: page_count,
                            callback: function (idx) {
                                cutPagination(idx, res);
                            }
                        });
                    }
                }
            }
        )
    };

    /**
     * 分页
     * @param page 从1开始
     */
    function cutPagination(page, res) {
        var start = (page - 1) * page_count;
        var end = start + page_count;
        if (end > res.length) {
            end = res.length;
        }
        $("#table tbody").html("");
        for (var i = start; i < end; i++) {
            var cashInfo = res[i];
            var cashId = cashInfo.cashId;

            var tr = document.createElement("tr");
            var td = document.createElement("td");
            var tdContent = document.createTextNode(i + 1);
            td.appendChild(tdContent);
            tr.appendChild(td);

            var td = document.createElement("td");
            var tdContent = document.createTextNode(cashInfo.cashNumber);
            td.appendChild(tdContent);
            tr.appendChild(td);

            var td = document.createElement("td");
            var tdContent = document.createTextNode(timestampToTime(cashInfo.createTime));
            td.appendChild(tdContent);
            tr.appendChild(td);

            var td = document.createElement("td");
            var name = "" == cashInfo.userName ? cashInfo.cashAccount : cashInfo.userName;
            var tdContent = document.createTextNode(name);
            td.appendChild(tdContent);
            tr.appendChild(td);

            var td = document.createElement("td");
            var tdContent = document.createTextNode(cashInfo.cashMoney + "KSH");
            td.appendChild(tdContent);
            tr.appendChild(td);

            var td = document.createElement("td");
            var tdContent = document.createTextNode(cashInfo.paymentType);
            td.appendChild(tdContent);
            tr.appendChild(td);

            var td = document.createElement("td");
            var tdContent = document.createTextNode(cashInfo.cashAccount);
            td.appendChild(tdContent);
            tr.appendChild(td);
            var td = document.createElement("td");
            var btn1 = document.createElement("button");
            btn1.setAttribute("type", "button");
            btn1.setAttribute("class", "btn btn-info btn-sm");
            btn1.setAttribute("cashId", cashId);

            btn1.onclick = function (ev) {
                cashfalse(this);
            }
            var tdContent = document.createTextNode("不通过");
            btn1.appendChild(tdContent);
            td.appendChild(btn1);

            var btn2 = document.createElement("button");
            btn2.setAttribute("type", "button");

            var btn2 = document.createElement("button");
            btn2.setAttribute("type", "button");
            btn2.setAttribute("class", "btn btn-success btn-sm");
            btn2.setAttribute("cashId", cashId);
            btn2.onclick = function (ev) {
                cashTrue(this);
            }
            var tdContent = document.createTextNode(" 通  过 ");
            btn2.appendChild(tdContent);
            td.appendChild(btn2);
            tr.appendChild(td);
            document.getElementById("tbody").append(tr);
            document.getElementById("tbody").innerHTML;
        }
    }

    findCashInfo();

    function cashTrue(colom) {
        var datas = {};
        datas.cashId = colom.getAttribute("cashId");
        datas.flag = 1;
        $.ajax({
            url: baseUrl.base + baseUrl.cashInfo + '/saveDetermineCashInfo',
            type: 'get',
            data: datas,
            success: function (data) {
                if (data.code == "0") {
                    showNotification('bottom', 'right', '提现确认成功');
                    findCashInfo();
                    findFundManagement();
                }
            }
        })
    };

    function cashfalse(colom) {
        var datas = {};
        datas.cashId = colom.getAttribute("cashId");
        datas.flag = 2;
        $.ajax({
            url: baseUrl.base + baseUrl.cashInfo + '/saveDetermineCashInfo',
            type: 'get',
            data: datas,
            success: function (data) {
                if (data.code == "0") {
                    showNotification('bottom', 'right', '提现驳回成功');
                    findCashInfo();
                    findFundManagement();
                }
            }
        })
    };
</script>
</html>